package com.toulouseculture.controller;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.toulouseculture.R;
import com.toulouseculture.bo.CulturePlace;

public class CulturePlaceAdapter extends BaseAdapter {

	List<? extends CulturePlace> mCulturePlaceList = new ArrayList<CulturePlace>();

	Context context;

	LayoutInflater inflater;

	private class ViewHolder {
		TextView tvName;
		TextView tvAddress;
	}

	public CulturePlaceAdapter(List<? extends CulturePlace> culturePlaceList, Context context) {
		super();
		this.mCulturePlaceList = culturePlaceList;
		this.context = context;

		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return mCulturePlaceList.size();
	}

	@Override
	public Object getItem(int position) {
		return mCulturePlaceList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return mCulturePlaceList.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;

		if (convertView == null) {

			holder = new ViewHolder();

			convertView = inflater.inflate(R.layout.cultureplacerow, null);

			holder.tvName = (TextView) convertView.findViewById(R.id.placeName);
			holder.tvAddress = (TextView) convertView.findViewById(R.id.placeAddress);

			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();

		}

		holder.tvName.setText(mCulturePlaceList.get(position).getName());
		holder.tvAddress.setText(mCulturePlaceList.get(position).getNoStreet() + " " + mCulturePlaceList.get(position).getAddress());

		return convertView;
	}

}